home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / OnRamp / bin / inityp.z / inityp
Encoding:
Text File  |  1997-07-30  |  3.5 KB  |  154 lines

  1. #!/usr/bin/perl5
  2. #
  3. # inityp
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: inityp,v 1.6 1997/04/17 23:38:19 shotes Exp $
  21.  
  22. $yproot_dir = "/var/yp";
  23. $XFR = "/usr/sbin/ypxfr";
  24. $hf = "/tmp/ypinit.hostlist\.".$$;
  25. $YPM = $yproot_dir."/ypmake";
  26. $chkconfig = "/sbin/chkconfig";
  27.  
  28. $masterp = "F";
  29. $slavep = "F";
  30. $host = "";
  31. $def_dom = "";
  32. $master = "";
  33. $got_host_list = "F";
  34. $exit_on_error = "F";
  35. $errors_in_setup = "F";
  36. $new_dm = "";
  37.  
  38. sub
  39. usage
  40. {
  41.     print "usage: inityp \[-m\] \[-d nis_domain \] [-l slave_server list\]\|\[-s master_server \]\n";
  42.     die;
  43. }
  44.  
  45. if ($> != 0) {
  46.     print "You have to be the superuser to run this.\n";
  47. #   die;
  48. }
  49.  
  50. $i = 0;
  51. while ($i <= $#ARGV) {
  52.     if ($ARGV[$i] eq "-m") {
  53.     $masterp = "T";
  54.     }
  55.     elsif ($ARGV[$i] eq "-d") {
  56.     $new_dm = $ARGV[$i+1];
  57.     if ($new_dm eq "") {
  58.         usage;
  59.     }
  60.     $i++;
  61.     }
  62.     elsif ($ARGV[$i] eq "-l") {
  63.     @slave_list = split(/,/, $ARGV[$i+1]);
  64.     $i++;
  65.     }
  66.     elsif ($ARGV[$i] eq "-s") {
  67.     $slavep = "T";
  68.     $master = $ARGV[$i+1];
  69.     if ($master eq "") {
  70.         usage;
  71.     }
  72.     $i++;
  73.     }
  74.     else {
  75.     usage;
  76.     }
  77.     $i++;
  78. }
  79.  
  80. chomp($host = `/usr/bsd/hostname`);
  81. chomp($def_dom = `/bin/domainname`);
  82.  
  83. if ( (! -d $yproot_dir) || (-f $yproot_dir) ) {
  84.     print "The directory $yproot_dir doesn't exist.\n";
  85.     die;
  86. }
  87.  
  88. if ($slavep eq "T") {
  89.     if ($host eq $master) {
  90.     print "The Master and Slave systems need to be distinct.\n";
  91.     die;
  92.     }
  93.     @ents = `/bin/ypwhich -m | /bin/egrep $master`;
  94.     undef @maps;
  95.     for ($i = 0; $i <= $#ents; $i++) {
  96.     ($maps[$i], $x) = split(/\s+/, $ents[$i]);
  97.     }
  98.     $dom = $def_dom;
  99. }
  100.  
  101. if ($masterp eq "T") {
  102.     if ($new_dom eq "") {
  103.     $dom = $def_dom;
  104.     }
  105.     else {
  106.     system("/bin/domainname", $new_dm);
  107.     $dom = $new_dm;
  108.     }
  109. }
  110.  
  111. if (-d "$yproot_dir/$dom") {
  112.     opendir(YPDIR, "$yproot_dir/$dom") || die "Unable to open directory $yproot_dir/$dom";
  113.     @fnames = readdir(YPDIR);
  114.     closedir(YPDIR);
  115.     for ($i = 0; $i <= $#fnames; $i++) {
  116.     if( ($fnames[$i] eq ".") || ($fnames[$i] eq "..") ) {
  117.         next;
  118.     }
  119.     if (-d $fnames[$i]) {
  120.         system ("/bin/rm", "-r", "-f", $fnames[$i]);
  121.         mkdir ($fnames[$i], 0755);
  122.     }
  123.     }
  124. }
  125. else {
  126.     mkdir ("$yproot_dir/$dom", 0755);
  127. }
  128.  
  129. if ($slavep eq "T") {
  130.     for ($i = 0; $i <= $#maps; $i++) {
  131.     system ($XFR, "-h", $master, "-c", "-d", $dom, $maps[$i]);
  132.     }
  133.     system ($chkconfig, "-f", "ypserv", "on");
  134.     system ($chkconfig, "-f", "yp", "on");
  135. }
  136. else {
  137.     chdir($yproot_dir);
  138.     unlink(<*.time>);
  139.     # prevent warning first time ypmake runs
  140.     open(LOGFL, ">$yproot_dir/ypmake.log.old");
  141.     close(LOGFL);
  142.  
  143.     open(YPSRV, ">$yproot_dir/ypservers") || die "Failed to open $yproot_dir/ypservers.\n";
  144.     print YPSRV "$host\n";
  145.     print YPSRV join('\n', @slave_list);
  146.     close(YPSRV);
  147.  
  148.     `$YPM NOPUSH=1`;
  149.  
  150.     system ($chkconfig, "-f", "ypmaster", "on");
  151.     system ($chkconfig, "-f", "ypserv", "on");
  152.     system ($chkconfig, "-f", "yp", "on");
  153. }
  154.